package com.kd.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.kd.bean.Blogs;
import com.kd.dao.IBlogsDao;
import com.kd.service.IBlogsService;

@Service
public class BlogsServiceImpl implements IBlogsService{

	@Autowired
	private IBlogsDao dao;
	
	/*public boolean upBlogsBylikenumInt(Integer blogs_id) throws Exception {
		// TODO Auto-generated method stub
		//����id�޸ĵ�����
		Blogs bs_id = dao.selectById(blogs_id);
		
		int likenum_int = bs_id.getLikenum_int();
		//点赞数+1
		likenum_int=likenum_int+1;
		bs_id.setLikenum_int(likenum_int);
		return dao.updateById(bs_id)>0;
	}*/
	
	public List<Blogs> selectBlogs() throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		return dao.selectByMap(map);
	}

	/*public List<Blogs> selectBlogsByUserId(Integer user_id) throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("user_id", user_id);
		return dao.selectByMap(map);
	}*/

	public List<Blogs> selectBlogsLike(String blogs_title, String blogs_content) throws Exception {
		// TODO Auto-generated method stub
		return dao.selectList(new EntityWrapper<Blogs>()
					.like("blogs_title", blogs_title)
					.orNew()
					.like("blogs_content", blogs_content)
				);
	}
	
	//博主点开个人管理 
	public boolean updateBlogs(Blogs bs) throws Exception {
		// TODO Auto-generated method stub
		return dao.updateById(bs)>0;
	}

	public boolean deleteBlogs(Integer blogs_id) throws Exception {
		// TODO Auto-generated method stub
		return dao.deleteById(blogs_id)>0;
	}

	public boolean insertBlogs(Blogs bs) throws Exception {
		// TODO Auto-generated method stub
		return dao.insert(bs)>0;
	}

	public List<Blogs> selectLimitBlogs(Integer pageOne) throws Exception {
		// TODO Auto-generated method stub
		pageOne=(pageOne-1)*10;
		List<Blogs> bsList = dao.selectPage(new Page<Blogs>(pageOne,10), null);
		return bsList;
	}

	public List<Blogs> selectBlogs_LikeById(Integer user_id, String blogs_title, String blogs_content)
			throws Exception {
		// TODO Auto-generated method stub
		List<Blogs> bsList = dao.selectList(new EntityWrapper<Blogs>()
					.like("blogs_title", blogs_title)
					.andNew()
					.like("blogs_content",blogs_content)
					.eq("user_id", user_id)
				);
		return bsList;
	}
	
}
